package program.Junction;

import Exceptions.IllegalCoordinateException;
import Exceptions.ShootException;
import program.Atom;
import program.SExprList;
import program.SExpression;
import program.Condition.Condition;
import roborally.Robot;

/**
 * 	A class representing the AND junction.
 * 
 * @author Jef Keijers/Bachelor of Science: Informatics
 * @version 1.0
 */
public class And extends Condition {
	
	/**
	 * This constructor instanstiate a new AND instance and sets the conditions to the given conditions.
	 * @param condition1
	 * @param condition2
	 */
	public And(Condition condition1,Condition condition2) {
		this.condition1=condition1;
		this.condition2=condition2;
	}
	
	
	/**
	 * This method returns true if both called methods return true. 
	 */
	@Override
	public boolean execute(Robot robot) throws ShootException, IllegalCoordinateException {
		return ((condition1.execute(robot)) && (condition2.execute(robot)));
	}
	
	/**
	 * This method returns a SExpression representation of the AND junction.
	 */
	@Override
	public SExpression toSExpression() {
		SExprList sexpr = new SExprList();
		sexpr.add(new Atom("and"));
		sexpr.add(condition1.toSExpression());
		sexpr.add(condition2.toSExpression());
		return sexpr;
	}
	/**
	 * Instance variable representing condition 1 of the AND junction.
	 */
	private Condition condition1;
	/**
	 * Instance variable representing condition 2 of the AND junction.
	 */
	private Condition condition2;
	



}
